training steps too long? add a spinny loading thingy. that way you can tell whether you've disconnected from the server or not
with spinny_loading_thingy("loading...", "loaded!"):
# your code to do whatever goes here
code:
```python
# save this file as spinner.py or whatever so you can do "from spinner import spinny_loading_thingy"
import threading
import time
import sys
class spinny_loading_thingy:
def __init__(self, start_message, completion_message):
self.start_message = start_message
self.completion_message = completion_message
self.spinner_chars = ['|', '/', '-', '\\']
self.spinner_running = False
self.spinner_thread = None
def _spinner_animation(self):
"""Display spinner animation"""
i = 0
while self.spinner_running:
sys.stdout.write(f'\r{self.start_message} {self.spinner_chars[i]}')
sys.stdout.flush()
time.sleep(0.1)
i = (i + 1) % len(self.spinner_chars)
def __enter__(self):
self.spinner_running = True
# Start the spinner in a separate thread
self.spinner_thread = threading.Thread(target=self._spinner_animation)
self.spinner_thread.start()
return self
def __exit__(self, exc_type, exc_val, exc_tb):
# Stop the spinner
self.spinner_running = False
self.spinner_thread.join()
# Clear the entire line and show completion message
sys.stdout.write('\r\033[K') # \r to return to start, \033[K to clear line
sys.stdout.write(f'{self.completion_message}\n')
sys.stdout.flush()
# Return False to not suppress any exceptions
return False
# Example usage
if __name__ == "__main__":
with spinny_loading_thingy("loading...", "loaded!"):
# Simulate some work
time.sleep(3)
```